package com.codemeta.bokit.douyin.config;

import com.codemeta.bokit.douyin.core.props.DouyinProps;
import com.codemeta.bokit.douyin.sdk.ApiClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * 抖音自动装配
 *
 * @author hice
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(DouyinProps.class)
public class DouyinAutoConfig {

    public DouyinAutoConfig(DouyinProps props) {
        log.debug("【bokit】抖音sdk自动装配初始化：{}", props);
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    @ConditionalOnMissingBean(ApiClient.class)
    public ApiClient apiClient(DouyinProps props) {
        ApiClient apiClient = new ApiClient(restTemplate());
        log.debug("【bokit】初始化抖音ApiClient：{}", apiClient.getAuthentications());
        return apiClient;
    }
}